package com.sondon.mayi.activity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.apache.http.Header;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;

import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.sondon.mayi.configs.URLConfigs;
import com.sondon.mayi.entity.RespondBaseEntity;
import com.sondon.mayi.fruit.R;
import com.sondon.mayi.ui.MyMultipleTopBar;
import com.sondon.mayi.ui.TopBarClickListener;
import com.sondon.mayi.util.AsyncHttpUtil;
import com.sondon.mayi.util.GsonUtil;
import com.sondon.mayi.util.LogUtil;
import com.sondon.mayi.util.ToastUtils;

/**
 * @Project : Fruit
 * @Package : com.sondon.mayi.activity
 * @Class : CommitActity
 * @Author : 蔡文锋
 * @DateTime：2015年7月7日 下午11:36:00
 * @Blog：http://blog.csdn.net/caiwenfeng_for_23
 * @Description : { 评论 }
 *
 */
@EActivity(R.layout.commit)
public class CommitActity extends BaseActivity {
	@ViewById
	MyMultipleTopBar topBar;
	@ViewById
	RatingBar ratingBar_zhi;//产品质量
	@ViewById
	RatingBar ratingBar_sudu;//送货速度
	@ViewById
	RatingBar ratingBar_fuwu;//服务质量
	@ViewById
	EditText commit_message;//评论文字
	@ViewById
	Button commit_smubit;//评论
	
	private String Order_no;
	@AfterViews
	public void initView(){
		topBar.setTopBarClickListener(new TopBarClickListener() {
			
			@Override
			public void rightBtnClick() {
				
			}
			
			@Override
			public void leftBtnClick() {
				onBackPressed();
			}
		});
		
		this.Order_no=getIntent().getExtras().getString("Order_no");
	}
	

	@Click({R.id.commit_smubit})
	public void onClick(View v){
		switch (v.getId()) {
		case R.id.commit_smubit://评论
			sumbitCommit();
			break;

		default:
			break;
		}
	}
	
	
	//提交评论
	public void sumbitCommit(){
		RequestParams params=new RequestParams();
		params.put("order_no", this.Order_no);
		params.put("contents", commit_message.getText().toString().trim());
		params.put("about_goods", ratingBar_zhi.getRating());
		params.put("about_mail", ratingBar_sudu.getRating());
		params.put("about_service", ratingBar_fuwu.getRating());
		AsyncHttpUtil.post(URLConfigs.Commit_ukey+myprefs.Ukey().get(), params, new TextHttpResponseHandler() {
			
			@Override
			public void onSuccess(int status, Header[] arg1, String json) {
				LogUtil.e(TAG, "Commit  json  :"+json);
				if(200==status){
					RespondBaseEntity entity=GsonUtil.GetFromJson(json, RespondBaseEntity.class);
					if(entity.isStatus()){
						finish();
					}else{
						ToastUtils.show(context, entity.getMsg());
					}
				}
			}
			
			@Override
			public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
				ToastUtils.show(context, R.string.network_unavailable);
			}
		});
	}
}
